package com.dingding.order.core.myorder.biz.impl;

import javax.annotation.Resource;

import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;

import com.dingding.common.core.base.code.BaseCodeMessage;
import com.dingding.common.core.base.dto.AbstractResponse;
import com.dingding.common.core.base.dto.ResponseEntity;
import com.dingding.order.core.myorder.biz.IGetHistoryOrderDetailService;
import com.dingding.order.core.myorder.dao.IGetMyOrderDao;
import com.dingding.order.dto.myorder.ReqHistoryOrderDetailDTO;
import com.dingding.order.dto.myorder.ResHistoryOrderDetailDTO;

/**
 * 
 * @ClassName: IGetHistoryOrderDetailService 
 * @Description: 获取历史订单详情Service
 * @author YHQ
 * @date 2016年9月22日 下午4:14:43
 * @since V2.5.0
 * 
 */
@Component("getHistoryOrderDetailService")
public class GetHistoryOrderDetailServiceImpl extends AbstractResponse<ResHistoryOrderDetailDTO, ReqHistoryOrderDetailDTO> implements IGetHistoryOrderDetailService {

	@Resource(name = "getMyOrderDao")
	IGetMyOrderDao getMyOrderDao;
	
	/**
	 * 
	 * @Title: getHistoryOrderDetail 
	 * @Description: 获取历史订单详情
	 * @param requestData 客户端请求参数
	 * @author YHQ 
	 * @return String    返回类型
	 * 
	 */
	public String getHistoryOrderDetail(String requestData){
		
		// 封装响应bean
		ResponseEntity<ResHistoryOrderDetailDTO> response = new ResponseEntity<ResHistoryOrderDetailDTO>();
		
		// 将请求转换成bean
		ReqHistoryOrderDetailDTO reqHistoryOrderDetailDTO = super.parseRequestJson(requestData);
		
		// 1.验证参数
		if (!validateParam(response, reqHistoryOrderDetailDTO)) {
			return super.responseBeanToJson(response);
		}
		
		// 获取历史订单详情
		ResHistoryOrderDetailDTO resHistoryOrderDetailDTOs = getMyOrderDao.getHistoryOrderDetail(reqHistoryOrderDetailDTO);
		
		if(resHistoryOrderDetailDTOs == null){
			response.setCode(HttpStatus.SC_FORBIDDEN);
			response.setErrorMessage(BaseCodeMessage.ORDER_IS_NOT_EXISTENT);
			response.setPromptMessage(BaseCodeMessage.ORDER_IS_NOT_EXISTENT);
			return super.responseBeanToJson(response);
		}
		
		response.setCode(HttpStatus.SC_OK);
		response.setResponseBody(resHistoryOrderDetailDTOs);
		
		return super.responseBeanToJson(response);
	}

}
